using GameFlowManager.Screens;
using Microsoft.Xna.Framework;
using Tribaan.Components;

namespace Tribaan
{
	/// <summary>
	/// This is the main type for your game
	/// </summary>
	public class TribaanGame : Game
	{
		#region Constants

		private const int SCREEN_WIDTH = 1280;
		private const int SCREEN_HEIGHT = 720;
		private const string CONTENT_ROOT = "Content";

		#endregion

		#region Variables

		private GraphicsDeviceManager _graphics;

		#endregion

		#region Constructors

		static TribaanGame()
		{
			Instance = new TribaanGame();
		}

		private TribaanGame()
		{
			_graphics = new GraphicsDeviceManager(this);
			_graphics.PreferredBackBufferWidth = SCREEN_WIDTH;
			_graphics.PreferredBackBufferHeight = SCREEN_HEIGHT;
			Content.RootDirectory = CONTENT_ROOT;

			Components.Add(new SolidColorBackgroundComponent(this) { Color = Color.Black });
			Components.Add(new ScreenManagerComponent(this));
		}

		#endregion

		#region Properties

		public static TribaanGame Instance { get; private set; }

		public IScreenManager ScreenManager
		{
			get
			{
				return Services.GetService<IScreenManager>();
			}
		}

		#endregion

		#region Methods

		protected override void LoadContent()
		{
			base.LoadContent();

			ScreenManager.EnterScreen(new MainMenuScreen() { TransitionOffTime = 1.5f });
		}

		protected override void Update(GameTime gameTime)
		{
			base.Update(gameTime);

			if (ScreenManager.ActiveScreen == null)
			{
				Exit();
			}
		}

		#endregion
	}
}